﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZephyrisNet_PC;

namespace TestConsole
{
    class AImodule
    {
        private NetworkMainClass networkManager;
        public PlayerEntity player;


        private float RandomNumber(float min, float max)
        {
            return UniqueRandNum.GetUniqueNumber(max, min);
        }

        public AImodule(NetworkMainClass networkManager)
        {
            this.networkManager = networkManager;

            float x = RandomNumber(-20.0f, 20.0f);
            float px = x / 10;

            float y = RandomNumber(-20.0f, 20.0f);
            float py = y / 10;

            float z = RandomNumber(-20.0f, 20.0f);
            float pz = z / 10;

            Microsoft.Xna.Framework.Vector3 initPosVec = new Microsoft.Xna.Framework.Vector3(px, py, pz);

            player = new PlayerEntity(Guid.NewGuid());
            player.pos = initPosVec;
        }

        public void NetworkUpdate()
        {
            StringBuilder networkPacketBuilder = new StringBuilder();

            networkPacketBuilder.Clear(); // Clean the network string

            networkPacketBuilder.Append("POSN:");
            networkPacketBuilder.Append(player.playerID);
            networkPacketBuilder.Append('|');
            networkPacketBuilder.Append(player.pos.X);
            networkPacketBuilder.Append('|');
            networkPacketBuilder.Append(player.pos.Y);
            networkPacketBuilder.Append('|');
            networkPacketBuilder.Append(player.pos.Z);
            networkPacketBuilder.Append('|');
            networkPacketBuilder.Append(player.rotQuat.X);
            networkPacketBuilder.Append('|');
            networkPacketBuilder.Append(player.rotQuat.Y);
            networkPacketBuilder.Append('|');
            networkPacketBuilder.Append(player.rotQuat.Z);
            networkPacketBuilder.Append('|');
            networkPacketBuilder.Append(player.rotQuat.W);
            networkPacketBuilder.Append('|');
            if (player.drawShieldFlash) networkPacketBuilder.Append(1);
            else networkPacketBuilder.Append(0);
            networkPacketBuilder.Append('|');
            if (player.drawArmourFlash) networkPacketBuilder.Append(1);
            else networkPacketBuilder.Append(0);

            networkManager.SendP2P(networkPacketBuilder.ToString());
        }
    }
}
